package com.xiangxiangjd.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xiangxiangjd.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xiangxiangjd.service.ReturnGoodsService;
import com.xiangxiangjd.bean.ReturnGoods;
import com.xiangxiangjd.controller.model.ApiResultModel;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 归还和物品 中间表 前端控制器
 * </p>
 *
 * @author 肖守凯
 * @since 2021-11-08
 */
@Controller
@RequestMapping("/api/returnGoods")
public class ReturnGoodsController extends BaseController{
    @Autowired
    ReturnGoodsService returnGoodsService;



     /** 主页面 */
    @GetMapping("admin/main.html")
    public String main(){
       return  "ReturnGoods/ReturnGoodsMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @GetMapping(value = "admin/addReturnGoodsHtml")
    public String addReturnGoodsHtml( ){
             return "ReturnGoods/ReturnGoodsAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @GetMapping(value = "admin/editReturnGoodsHtml")
    public String editReturnGoodsHtml(String id ,Model model ){
           model.addAttribute("returnGoods",returnGoodsService.selectReturnGoodsByIdReturnGoods(id));
             return "ReturnGoods/ReturnGoodsEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @PostMapping(value = "admin/showReturnGoodsHtml")
    public String showReturnGoodsHtml(String id ,Model model ){
           model.addAttribute("returnGoods",returnGoodsService.selectReturnGoodsByIdReturnGoods(id));
             return "ReturnGoods/ReturnGoodsShow";
    }


    /** 分页查询ReturnGoods
     * @param page  页码
     * @param limit  查几条
     * @param returnGoods  前端传进的参数
     * @return 返回统一分页信息
     */
    @PostMapping(value = "admin/findReturnGoodsByPage")
    @ResponseBody
    public ResultPage findReturnGoodsByPage(Integer page, Integer limit,ReturnGoods returnGoods){
             return returnGoodsService.findReturnGoodsByPage(page,limit,returnGoods);
    }

    /** 添加ReturnGoods
     * @param returnGoods  前端传进的参数
     * @return 返回统一信息
     */
    @PostMapping(value = "admin/addReturnGoods")
    @ResponseBody
    public ApiResultModel saveReturnGoods(ReturnGoods returnGoods  ){
             return returnGoodsService.addReturnGoods(returnGoods);
    }

    /** 编辑ReturnGoods
     * @param returnGoods  前端传进的参数
     * @return 返回统一信息
     */
    @PostMapping(value = "admin/editReturnGoods")
    @ResponseBody
    public ApiResultModel editReturnGoods(ReturnGoods returnGoods  ){
             return returnGoodsService.editReturnGoods(returnGoods);
    }

    /** 删除ReturnGoods
     * @param ids  前端传进的ID
     * @return 返回统一信息
     */
    @PostMapping(value = "admin/delReturnGoods")
    @ResponseBody
    public ApiResultModel delReturnGoods(@RequestParam("datas") ArrayList ids){


             return returnGoodsService.delReturnGoodss(ids);
    }




}
